import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import axios from "axios";
import VueAxios from "vue-axios";
import Cookies from "js-cookie"; //引用cookies
import "nprogress/nprogress.css"; //引用进度样式
//路由守卫
router.beforeEach((to, from, next) => {
  // console.log(Cookies)
  //判断如果有cookin值
  if (Cookies.get("token") || to.path == "/Login" || to.path == "404") {
    next();
  } else {
    next({ path: "/Login", query: { transfer: to.path } });
  }
});
const app = createApp(App);
app.use(VueAxios, axios);
app.use(store);
app.use(router);
app.directive("permission", {
  mounted(el, binding) {
    let val = binding.value;
    var user = store.getters.user||[];
    if (user.indexOf(val) === -1) {
      el.remove();
    }
  },
});
app.mount("#app");
